//3
//14
//10 4 5
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initNum;
let initArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number( line.trim())
    } else if (initNum === undefined) {
        initNum = Number( line.trim())
    } else {
        initArr = line.trim().split(" ").map(Number)
        console.log(getResult(n, initNum, initArr))
        // clear
        n = initNum = undefined
        initArr.length = 0
    }

})

function getResult(n, initNum, initArr) {
    let min = 0
    let max = Math.max(...initArr);
    let result = Infinity;

    while(min <= max) {
        let mid = Math.floor((min + max)/2)
        let flag = true;
        let remain = initNum - initArr[0]
        for (let i = 1; i < initArr.length ; i++) {
            if((remain + mid) < initArr[i]) {
                flag = false;
                break
            } else {
                remain = -initArr[i] + remain + mid
            }
        }
        if(flag) {
            result = Math.min(result, mid);
            max = mid - 1
        } else {
            min = mid + 1
        }
    }
    return result
}